package com.ggh.controller;
import com.ggh.entity.Pay;
import com.ggh.entity.TypeBean;
import com.ggh.service.PayService;
import com.ggh.vo.UserToken;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * 绑定
 * @author jj
 * @date 2019/10/14 16:35
 */
@Controller
@RequestMapping("/pay")
public class PayController {
    @Autowired
    private PayService payService;
    /**
    * @description :查询是否有绑定
    * @param pay 
    * @return: com.ggh.vo.UserToken
    * @date : 2019/10/17 9:59
    * @author : jj
    * @throws
    */
    @RequestMapping(value = "/query",method = RequestMethod.POST)
    @ResponseBody
    public UserToken query(Pay pay){
        Pay query = payService.query(pay);
        /*支付宝*/
        if (pay.getType()==1){
            if (query==null){
                return  UserToken.newInstance(pay.getUserid(),"HallTiXianZFBInfo",false, TypeBean.SUCCESS);
            }else {
                return  UserToken.newInstance(pay.getUserid(),"HallTiXianZFBInfo",true, TypeBean.SUCCESS);
            }
        }
        /*银行卡*/
        if (query==null){
            return  UserToken.newInstance(pay.getUserid(),"HallTiXianBankInfo",false, TypeBean.SUCCESS);
        }else {
            return  UserToken.newInstance(pay.getUserid(),"HallTiXianBankInfo",true, TypeBean.SUCCESS);
        }


    }

    /**
     * 返回数据
     * @param pay
     * @return
     */
    @RequestMapping(value = "/rtData",method = RequestMethod.POST)
    @ResponseBody
    public  UserToken rtData(Pay pay){
        Pay query = payService.query(pay);
        /*支付宝*/
        if (pay.getType()==1) {
            return UserToken.newInstance(pay.getUserid(), "HallTiXianBindZFB", query, TypeBean.SUCCESS);
        }
        /*银行卡*/
        return UserToken.newInstance(pay.getUserid(), "BankCard", query, TypeBean.SUCCESS);


    }
    /**
     * @description :绑定账号
     * @param pay
     * @return: java.util.List<com.ggh.entity.UserRecord>
     * @date : 2019/10/14 15:44
     * @author : jj
     * @throws
     */
    @RequestMapping(value = "/addpay",method = RequestMethod.POST)
    @ResponseBody
    public UserToken addOrupdate(Pay pay) {
            boolean result = payService.addpay(pay);
            /*支付宝*/
            if (pay.getType()==1) {
                if (result) {
                    return UserToken.newInstance(pay.getUserid(), "HallTiXianBindZFB", pay, TypeBean.SUCCESS);
                }
                return UserToken.newInstance(pay.getUserid(), "HallTiXianBindZFB", "参数错误", TypeBean.SUCCESS);
            }
            /*银行卡*/
            if (result) {
                return UserToken.newInstance(pay.getUserid(), "HallTiXianBindBank", pay, TypeBean.SUCCESS);
            }
            return UserToken.newInstance(pay.getUserid(), "HallTiXianBindBank", "参数错误", TypeBean.SUCCESS);

    }
}
